package shujia.day08;

/*
    String类中的转换功能：
        byte[] getBytes()
        char[] toCharArray()
        static String valueOf(char[] chs)
        static String valueOf(int i)
        String toLowerCase()
        String toUpperCase()
        String concat(String str)

 */
public class StringDemo5 {
    public static void main(String[] args) {
        String s1 = "数加";

        // byte[] getBytes() 将字符串转成字节数组的形式【受编码的影响】
        byte[] bytes = s1.getBytes();
        printIntArray(bytes);

        // char[] toCharArray()
        char[] chars = s1.toCharArray(); // 将字符串转成字符数组的形式
        printIntArray(chars);

        //static String valueOf(char[] chs) // 将字符数组转字符串
        String s2 = String.valueOf(chars);
        System.out.println(s2);

        //static String valueOf(int i) // 将数值转成字符串
        String s3 = String.valueOf(10);
        System.out.println(s3); // "10"

        //String toLowerCase() 将字符串转小写
        String s4 = "HellO";
        String s5 = s4.toLowerCase();
        System.out.println(s5);

        //String toUpperCase() 将字符串转大写
        String s6 = s5.toUpperCase();
        System.out.println(s6);

        // String concat(String str) 字符串拼接
        String s7 = "shujia";
        String s8 = "keji";
        System.out.println(s7+s8);
        System.out.println(s7.concat(s8));


    }
    public static void printIntArray(char[] array) {
        for (int i = 0; i < array.length; i++) {
            if (i == 0) {
                System.out.print("[" + array[i] + ",");
            } else if (i == array.length - 1) {
                System.out.println(array[i] + "]");
            } else {
                System.out.print(array[i] + ",");
            }
        }
    }


    public static void printIntArray(byte[] array) {
        for (int i = 0; i < array.length; i++) {
            if (i == 0) {
                System.out.print("[" + array[i] + ",");
            } else if (i == array.length - 1) {
                System.out.println(array[i] + "]");
            } else {
                System.out.print(array[i] + ",");
            }
        }
    }
}
